#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dynaArrlib.h"

//#define SIMPLE_ARRAY
#ifdef SIMPLE_ARRAY
int main()
{/*{{{*/
	int i, j;
	/********一维动态数组***********/
	int *array1 = NULL;
	int length = 6;

	array1 = (int *)calloc(length, sizeof(int));
	if(array1 == NULL) {
		perror("array1 calloc");
		return -1;
	}

	for(i = 0; i < length; i++)
	{
		array1[i] = i + 1;
		printf("%d\t", array1[i]);
	}
	printf("\n");
	free(array1);

	/********二维动态数组***********/
	int col = 4;
	int row = 6;
	int **array2 = NULL;
	
	array2 = (int **)malloc(col * sizeof(int *)); /* 第一维 */
	if(array2 == NULL) {
		perror("array2 malloc");
		return -1;
	}
	for(i = 0; i < col; i++)
	{
		array2[i] = (int *)malloc(row * sizeof(int)); /* 第二维 */
		if(array2[i] == NULL) {
			perror("array2 malloc");
			return -1;
		}
	}

	for(i = 0; i < col; i++)
	{
		for(j = 0; j < row; j++)
		{
			array2[i][j] = i * row + j + 1;
			printf("%d\t", array2[i][j]);
		}
		printf("\n");
	}

	for(i = 0; i < col; i++)
	{
		free(array2[i]);
	}
	free(array2);

	return 0;
}/*}}}*/

#else
int main()
{
	int i;
	struct _test {
		int data;
		char flag;
	}a[80];

	for(i = 0; i < 80; i++)
	{
		a[i].data = i;
	}

	cel_array_t *ptr;

	ptr = new_cel_array_opacity(16);
	for(i = 0; i < 80; i++)
	{
		cel_array_add(ptr, &a[i]);	
	}

	for(i = 0; i < 80; i++)
	{
		printf("i = %d\n",((struct _test *)cel_array_get(ptr, i))->data);	
	}
	free_cel_array(&ptr, NULL);

	return 0;
}

#endif //SIMPLE_ARRAY
